package com.common.frame.base

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.common.frame.R

abstract class BaseDialog<VB : ViewDataBinding>(context: Context) :
        Dialog(context, R.style.dialog_style), View.OnClickListener {


    lateinit var mBinding: VB
    var width: Int = -2

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = DataBindingUtil.inflate(LayoutInflater.from(context), getLayoutId(), null, false)
        setContentView(mBinding.root)

        initView()
        initListener()

        window?.setGravity(getGravity())


    }
    fun cancelable(flag: Boolean = false, cancel: Boolean = false) {
        setCancelable(flag)
        setCanceledOnTouchOutside(cancel)
    }


    fun setWidthHeight(width: Int = WindowManager.LayoutParams.WRAP_CONTENT, height: Int = WindowManager.LayoutParams.WRAP_CONTENT) {
        window?.let {
            it.attributes.width = width
            it.attributes.height = height
        }
    }
    fun hideBackgroundShadows() {

        window?.attributes?.dimAmount = 0f

    }

    override fun onClick(v: View) {

    }

    abstract fun initView()

    abstract fun initListener()

    abstract fun getLayoutId(): Int

    abstract fun getGravity(): Int}